package com.XDApp.xdbase;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

/**
 * 中间容器的管理工具
 * 
 * @author Administrator
 * 
 */
public class UIManager {
	private static UIManager instance = new UIManager();

	public static UIManager getInstance() {
		return instance;
	}

	private UIManager() {
	}

	/**
	 * 界面切换
	 * 
	 * @param target
	 */
	public void changeFragment(Fragment target, boolean isAddStack,
			Bundle bundle) {
		if (bundle != null) {
			target.setArguments(bundle);
		}

		FragmentManager manager = GloableParams.MAIN
				.getSupportFragmentManager();
		FragmentTransaction transaction = manager.beginTransaction();

		transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

		// transaction.add(R.id.ii_middle, moreFragment);//
		// 第一参数：中间容器的id，第二个参数：添加的Fragment
		transaction.replace(R.id.ii_middle, target);
		
		// 返回键操作
		if (isAddStack)
			transaction.addToBackStack(null);

		transaction.commit();
	}
}
